<?php

// File Dependencies
using('Library.DateTime');
using('Library.DataTypes.Array.Conversion');

/**
 * Warlock Profiler
 *
 * Provides information useful for determining bottlenecks and overhead issues
 * at any point within the warlock execution.
 *
 * Warlock is free software. This version may have been modified pursuant
 * to the GNU General Public License, and as distributed it includes or
 * is derivative of works licensed under the GNU General Public License or
 * other free or open source software licenses.
 *
 * @author     David Cole <neophyte@sourcetutor.com>
 * @package    warlock
 * @subpackage library
 * @license    GNU/GPL v2
 *
 */
class Debug_Profiling extends Object
{
    /**
     * An array of all logged events
     *
     * @var array
     * @access private
     */
    var $_benchmarks = array();


    var $_stack = array();

    /**
     * Class Contructor
     */
    function __construct()
    {
        // Add class instance to vault
        Vault::Add('Debug_Profiling', &$this);
    }

    function Start($desc)
    {
        $this->_benchmarks[] = array('description' => $desc,
                                     'depth'       => count($this->_stack),
                                     'start'       => DateTime_MicroTime(true));

        $this->_stack[] = (count($this->_benchmarks) - 1);
    }

    function Stop()
    {
        $id = array_pop($this->_stack);
        $this->_benchmarks[$id]['end']      = DateTime_MicroTime(true);
        $this->_benchmarks[$id]['duration'] = ($this->_benchmarks[$id]['end'] - $this->_benchmarks[$id]['start']);
    }

    function GetLog()
    {
        return $this->_benchmarks;
    }
}

function Debug_Profiling_IncludedFiles()
{
    $files = get_included_files();
    $data  = array();

    foreach ($files as $file)
        $data[] = array('file' => str_replace(W_ENV_PATH, '', $file),
                        'size' => filesize($file));

    return $data;
}

?>